package com.bootdo.app.service.impl;

import cn.hutool.db.Page;
import com.bootdo.app.dao.LevelProfitMapper;
import com.bootdo.app.service.LevelProfitService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.R;
import com.bootdo.common.utils.ShiroUtils;
import com.bootdo.system.domain.TbLevelProfit;
import com.bootdo.system.domain.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @create 2021-03-10 21-57
 */
@Service
public class LevelProfitServiceImpl implements LevelProfitService {

    @Autowired
    private LevelProfitMapper profit;

    @Override
    public PageUtils selectLevelProfitList() {
        Map map = new HashMap();
        UserDO user = ShiroUtils.getUser();
        if(user.getUserId() != 1){
            map.put("adminId",user.getUserId());
        }
        List list = profit.selectProfitList(map);
        int i = profit.selectProfitCount(map);
        PageUtils page = new PageUtils(list,i);
        return page;
    }

    @Override
    public Map selecLevelProfitMap(Integer type) {
        Map map = new HashMap();
        map.put("userType",type);
        Map map1 = profit.selectProfitByType(map);
        return map1;
    }

    @Override
    public R insertLevelProfit(TbLevelProfit profitz) {
        profit.insertLevelProfit(profitz);
        return R.ok();
    }

    @Override
    public R updateLevelProfit(TbLevelProfit profitz) {
        profit.updateLevelProfit(profitz);
        return R.ok();
    }

    @Override
    public R deleteLevelProfit(Long id) {
        profit.deleteLevelProfit(id);
        return R.ok();
    }
}
